/**
 * 主功能页面，用于加载首页，包括左边树和右边主要内容
 * author:zhushy
 * date:2016年9月1日12:03:42
 */
var shellkmList = {
	/**
	 * 初始化左边树结构
	 */
	initShellKmList:function(){
		//参数
		var param = {
			"pk_user":window.localStorage.userid,
			"pageSize":common.pageSize,
			"pageNum":common.currentPage,
			"publish_key":window.sessionStorage.searchKmKey,
			"km_type":window.sessionStorage.searchKmType,
			"paramOrder":window.sessionStorage.searchOrderKey,
			"orderRule":window.sessionStorage.searchOrderRule
		};
 
        var seachStr = "";
        if(window.sessionStorage.searchKmType != ""){
    		$("#mainCategoryList li a").each(function(){
    			var data_pk = $(this).attr("data-pk");
    			if(data_pk == window.sessionStorage.searchKmType){
    				seachStr += "<span>" + $(this).html() + "；</span>";
    			}
    		});
        }else{
        	seachStr += "<span>全部；</span>";
        }
        
        if($("#searchInput").val() != ""){
        	seachStr += "<span>" + $("#searchInput").val() + "；</span>";
        }
        
		$("#currentSearchList_shellkmList").html(seachStr);
		
		//转圈
		common.showLoading();
		var url = "/PCpublish/queryKmpublishPoJoLikePage";
		common.interfaceAjaxFunction(url,param,shellkmList.queryShellKmListSuccess);
	},
	/**
	 * 调用ajax取得数据列表结果处理
	 */
	queryShellKmListSuccess:function(json){
		//成功时候
    	if(json.status == "0"){
    		//加载设置后的主页面
			shellkmList.showQueryShellKmList(json);
    	}else{
    		//给出信息提示
    		$("#shellKmListTable tbody").append("<tr><td colspan='7'>"+json.message+"</td></tr>");
    	}
    	//转圈提示去除
    	common.hideLoading();
	},
	/**
	 * 显示列表
	 */
	showQueryShellKmList:function(json){
		var jsonData = json.data;
		//清空
		$("#shellKmListTable tbody").html("");
		if(json.data.length > 0){
			 //循环赋值
			for(var i=0;i<jsonData.length;i++){
				var jsonDataRow = jsonData[i];
				//console.log(jsonDataRow);
				//循环产生html
				var publishName = jsonDataRow.pk_publish_user == undefined ? "" : jsonDataRow.pk_publish_user;
				var rowHtml = "<tr>"
						+"  <td><a class='blue-color waitcallback-content' target='_blank' href='html/kmMaintanceReading.html?pk_publish="+jsonDataRow.pk_km_publish+"'>"+jsonDataRow.publish_title+"</a></td>"
						+"  <td>"+jsonDataRow.publish_key+"</td>"
						+"  <td>"+jsonDataRow.knowledge_category_name+"</td>"
						+"  <td>"+jsonDataRow.nuu+"</td>"
						+"  <td>"+jsonDataRow.ter+"</td>"
						+"  <td>"+publishName+"</td>"
						+"  <td>"+jsonDataRow.publish_time+"</td>"
						+"</tr>";
				$("#shellKmListTable tbody").append(rowHtml);
			}
		}else{
			//无数据
			$("#shellKmListTable tbody").append("<tr><td colspan='7'>暂无知识数据</td></tr>");
		}
		//列排序
		$(".title").unbind().on("click",function(){
			//console.log($(this).attr("data-type")+"====="+
			//排序图片
			var down = '<img src="../admin/images/down.png"/>';
			var uap = '<img src="../admin/images/uap.png"/>';
			//排序规则 首先清空所有的图片，然后原先的规则判断
			if ($(this).attr("data-type")=="ASC") {
				$(".waitcallback-uap").html("");
				window.sessionStorage.searchOrderRule="DESC";
				$(this).attr("data-type","DESC");
				$(this).children(".waitcallback-uap").html(down);
			} else {
				$(".waitcallback-uap").html("");
				window.sessionStorage.searchOrderRule="ASC";
				$(this).attr("data-type","ASC");
				$(this).children(".waitcallback-uap").html(uap);
			}
			//保存数据
			window.sessionStorage.searchOrderKey=$(this).attr("id");
			// window.sessionStorage.comment_orderRule=$(this).attr("data-type");
		
			shellkmList.initShellKmList();
		});

		//产生分页结构
		common.getPageDivide(json.count,"pageDivideContainer",shellkmList.initShellKmList);
	},
	initShellKmListOrder:function(){
		//第一次初始化排序规则
		window.sessionStorage.searchOrderRule="DESC";
		
		var str = window.sessionStorage.searchOrderKey;
		//console.log(str);
		$("#"+str).children(".waitcallback-uap").html('<img src="../admin/images/down.png"/>');
	},
	
	initialize:function(){
		// 排序初始化
		shellkmList.initShellKmListOrder();
		//高度初始化
		shellkmList.initShellKmList();
	}
};